import 'package:flutter/material.dart';
import 'package:flutter_vant_kit/main.dart';
import 'package:pax_info_app/model/sys_info.dart';
import 'package:pax_info_app/utils/uidata.dart';

class AutoClock extends StatefulWidget {
  const AutoClock({Key? key}) : super(key: key);

  @override
  _AutoClockState createState() => _AutoClockState();
}

class _AutoClockState extends State<AutoClock> {

  late bool _autoClock;
  List<String> images = [
    "https://img.yzcdn.cn/vant/leaf.jpg",
    "https://img.yzcdn.cn/vant/tree.jpg",
    "https://img.yzcdn.cn/vant/sand.jpg",
  ];

  Widget title(String title) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 20),
      child: Text(title, style: const TextStyle(fontSize: 16, color: UIData.textNormal)),
    );
  }

  @override
  void initState() {
    _autoClock = SysInfo.instance.autoClock??false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: UIData.windowBg,
      appBar: AppBar(
        backgroundColor: const Color.fromRGBO(143, 148, 251, 1),
        title: const Text('自动打卡'),
      ),
      body: SingleChildScrollView(
          padding: const EdgeInsets.all(0.0),
          child: Column(
            children: <Widget>[
              const SizedBox(height: 10.0,),
              CellGroup(
                border: false,
                children: [
                  Cell(
                      size: 'large',
                      title: '是否开启自动打卡',
                      customRight: SizedBox(
                        height: 20.0,
                        child: Switch(
                          value: _autoClock,
                          activeColor: UIData.primaryColor,
                          onChanged: (val) {
                            _autoClock = val;
                            SysInfo.instance.autoClock = _autoClock;
                            SysInfo.instance.save();
                            setState(() {});
                          },
                        ),
                      )
                  ),
                ],
              ),

              Offstage(
                offstage: !_autoClock,
                child: Container(
                  width: SysInfo.instance.deviceSize.width,
                  color: UIData.white,
                  margin: const EdgeInsets.only(top: 10.0),
                  padding: const EdgeInsets.only(bottom: 20.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      title('请选择你的靓照'),
                      ImageWall(
                        images: images,
                        count: 6,
                        multiple: true,
                        onUpload: (files) async {
                          print('>>>> files: ${files.toString()}');
                          return ['https://img.yzcdn.cn/vant/leaf.jpg'];
                        },
                        onChange: (image) {
                          print('>>>>> image: $image');
                        },
                      ),
                    ],
                  ),
                ),
              ),
            ],
          )),
    );
  }
}
